package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/4 19:01
 */
public class J23 {


     public class ListNode {
         int val;
         ListNode next;
         ListNode(int x) { val = x; }
     }

    /** https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/ */
    public ListNode reverseList(ListNode head) {

        // 反转链表
        ListNode cur = head;
        ListNode pre = null;
        ListNode next = null;
        while (cur != null) {
            next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }
}
